//
//  TTMessageView.m
//  TTLoveCar
//
//  Created by 王洋 on 16/10/12.
//  Copyright © 2016年 王洋. All rights reserved.
//

#import "TTMessageView.h"

@implementation TTMessageView

+ (instancetype)messageViewWithTitle:(NSString *)title backgroundColor:(UIColor *)color {
    
    TTMessageView *tmpView    = [[TTMessageView alloc] initWithFrame:CGRectMake(0, 0, TTScreenWidth, (IS_IPHONE_X ? 54 : 20))];
    tmpView.backgroundColor = color;
    
    UILabel *label      = [[UILabel alloc] initWithFrame:CGRectMake(0, (IS_IPHONE_X ? 34 : 0), TTScreenWidth, 20)];
    label.textAlignment = NSTextAlignmentCenter;
    label.font          = [UIFont systemFontOfSize:10.f];
    label.text          = title;
    label.textColor     = [UIColor whiteColor];
    [tmpView addSubview:label];
    
    return tmpView;
}

- (void)showWithDuration:(NSTimeInterval)seconds {
    
    self.alpha = 0.f;
    
    [UIView animateWithDuration:seconds delay:0 usingSpringWithDamping:1.f initialSpringVelocity:0.f options:0 animations:^{
        
        self.alpha = 1.f;
        
    } completion:^(BOOL finished) {
        
    }];
    
}

- (void)hideWithDuration:(NSTimeInterval)seconds {
    if (seconds == 0){
        [self removeFromSuperview];
    }else{
        [UIView animateWithDuration:seconds delay:0 usingSpringWithDamping:1.f initialSpringVelocity:0.f options:0 animations:^{
            
            self.alpha = 0.f;
            
        } completion:^(BOOL finished) {
            
            [self removeFromSuperview];
            
        }];
    }
}

- (void)dealloc {
    NSLog(@"释放了");
}

@end
